import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { BackEndTestComponent } from './pages/back-end-test/back-end-test.component';
import { HomeComponent } from './pages/home/home.component';
import { LoginComponent } from './pages/login/login.component';
import { RegisterComponent } from './pages/register/register.component';
import { NotFoundComponent } from './pages/not-found/not-found.component';
import { UserComponent } from './pages/user/user.component';
import { FrontComponent } from './pages/front/front.component';
import { AuthGuard } from './shared/guards/auth.guard';
import { LoginGuard } from './shared/guards/login.guard';
import { FrontGuard } from './shared/guards/front.guard';

const routes: Routes = [
  { path: 'home', redirectTo: 'home/login', pathMatch: 'full' },
  {
    path: 'home',
    component: HomeComponent,
    canActivate: [LoginGuard],
    children: [
      {
        path: 'login',
        component: LoginComponent,
        pathMatch: 'full',
        canActivate: [LoginGuard],
        data: { animation: 'login' }
      },
      {
        path: 'register',
        component: RegisterComponent,
        pathMatch: 'full',
        canActivate: [LoginGuard],
        data: { animation: 'register' }
      }
    ],
    data: { animation: 'home' }
  },
  {
    path: 'back-end-test',
    component: BackEndTestComponent,
    pathMatch: 'full',
    data: { animation: 'back-end-test' }
  },
  {
    path: 'user',
    component: UserComponent,
    pathMatch: 'full',
    canActivate: [AuthGuard],
    data: { animation: 'user' }
  },
  {
    path: 'front/:id',
    component: FrontComponent,
    pathMatch: 'full',
    canActivate: [AuthGuard, FrontGuard],
    data: { animation: 'front' }
  },
  {
    path: 'error',
    component: NotFoundComponent
  },
  {
    path: '',
    redirectTo: 'home/login',
    pathMatch: 'full'
  },
  {
    path: '**',
    redirectTo: 'error'
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}
